package com.cwd.arm.application.service.write;

import com.cwd.arm.application.dto.confirmIncome.ConfirmIncomeAddDto;
import com.cwd.arm.application.dto.confirmIncome.ConfirmIncomeUpdateDto;
import com.cwd.arm.application.service.write.facade.ConfirmIncomeWriteService;
import com.cwd.arm.domain.entity.ConfirmIncomeEntity;
import com.cwd.arm.domain.repository.ConfirmIncomeRepository;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
* Description:确认收入
* Created on 2021年11月16日
* @author  yan
*/
@Repository
@Primary
public class ConfirmIncomeWriteServiceImpl implements ConfirmIncomeWriteService{

    @Autowired
    private ConfirmIncomeRepository confirmIncomeRepository;

    @Transactional
    @Override
    public void save(ConfirmIncomeAddDto addDto) {
        confirmIncomeRepository.save(convertToEntity(addDto));
    }

    @Transactional
    @Override
    public void update(ConfirmIncomeUpdateDto updateDto) {
        confirmIncomeRepository.update(convertToEntity(updateDto));
    }

    @Transactional
    @Override
    public void del(Long id) {
        confirmIncomeRepository.del(id);
    }

    private ConfirmIncomeEntity convertToEntity(ConfirmIncomeAddDto addDto){
        ConfirmIncomeEntity entity = new ConfirmIncomeEntity();
        BeanUtils.copyProperties(addDto,entity);
        return entity;
    }

    private ConfirmIncomeEntity convertToEntity(ConfirmIncomeUpdateDto updateDto){
        ConfirmIncomeEntity entity = new ConfirmIncomeEntity();
        BeanUtils.copyProperties(updateDto,entity);
        return entity;
    }
}
